package org.dromara.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.app.domain.vo.SkWithdrawalLogVo;
import org.dromara.app.domain.bo.SkWithdrawalLogBo;
import org.dromara.app.service.ISkWithdrawalLogService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 提现信息LOG
 *
 * @author Evacuation
 * @date 2024-07-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/SkWithdrawalLog")
public class SkWithdrawalLogController extends BaseController {

    private final ISkWithdrawalLogService skWithdrawalLogService;

    /**
     * 查询提现信息LOG列表
     */
    @SaCheckPermission("app:SkWithdrawalLog:list")
    @GetMapping("/list")
    public TableDataInfo<SkWithdrawalLogVo> list(SkWithdrawalLogBo bo, PageQuery pageQuery) {
        return skWithdrawalLogService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出提现信息LOG列表
     */
    @SaCheckPermission("app:SkWithdrawalLog:export")
    @Log(title = "提现信息LOG", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SkWithdrawalLogBo bo, HttpServletResponse response) {
        List<SkWithdrawalLogVo> list = skWithdrawalLogService.queryList(bo);
        ExcelUtil.exportExcel(list, "提现信息LOG", SkWithdrawalLogVo.class, response);
    }

    /**
     * 获取提现信息LOG详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("app:SkWithdrawalLog:query")
    @GetMapping("/{id}")
    public R<SkWithdrawalLogVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(skWithdrawalLogService.queryById(id));
    }

    /**
     * 新增提现信息LOG
     */
    @SaCheckPermission("app:SkWithdrawalLog:add")
    @Log(title = "提现信息LOG", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SkWithdrawalLogBo bo) {
        return toAjax(skWithdrawalLogService.insertByBo(bo));
    }

    /**
     * 修改提现信息LOG
     */
    @SaCheckPermission("app:SkWithdrawalLog:edit")
    @Log(title = "提现信息LOG", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SkWithdrawalLogBo bo) {
        return toAjax(skWithdrawalLogService.updateByBo(bo));
    }

    /**
     * 删除提现信息LOG
     *
     * @param ids 主键串
     */
    @SaCheckPermission("app:SkWithdrawalLog:remove")
    @Log(title = "提现信息LOG", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(skWithdrawalLogService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 确认打款
     */
    @Log(title = "确认打款", businessType = BusinessType.UPDATE)
    @DeleteMapping("/sumbitConfirmPayment")
    public R<Void> sumbitConfirmPayment(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(skWithdrawalLogService.sumbitConfirmPayment(List.of(ids), true));
    }
    /**
     * 确认打款
     */
    @Log(title = "拒绝打款", businessType = BusinessType.UPDATE)
    @GetMapping("/withdrawimmediatelyjujue")
    public R<Void> withdrawimmediatelyjujue(Long id) {
        return toAjax(skWithdrawalLogService.withdrawimmediatelyjujue(id, true));
    }


}
